package com.app.service.basesetting;

import com.app.SpringAnnotationDef;
import com.app.dao.admin.AdminDao;
import com.app.dao.basesetting.GoodsDao;
import com.app.model.Goods_Info;
import com.app.model.Goods_InfoToPackage;
import com.app.model.Goods_Type;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: cnprinces
 * Date: 13-1-24
 * Time: 下午4:26
 * To change this template use File | Settings | File Templates.
 */

@Service(SpringAnnotationDef.GOODS_SERVICE)
public class GoodsService {
    @Resource(name = SpringAnnotationDef.GOODS_DAO)
    private GoodsDao dao;


    public GoodsDao getDao() {
        return dao;
    }

    public void setDao(GoodsDao dao) {
        this.dao = dao;
    }

    /**
     * 获取他旗下的所有商品
     *
     * @param goodsType
     * @return
     */
    public List<Goods_Info> loadGoodsInfoByType(Goods_Type goodsType) {
        if (goodsType.getParentId() == 0) {
            return this.getDao().getGoodsTypeByParentId(goodsType);
        } else {
            return this.getDao().getGoodsTypeById(goodsType);
        }
    }

    public List<Goods_Info> loadGoodsInfoList() {

        return dao.loadGoodsInfoList();  //To change body of created methods use File | Settings | File Templates.
    }

    public List<Goods_Info> loadGoodsInfoByPackageId(Integer id) {
        List<Goods_Info> goods_infoList = new ArrayList<Goods_Info>();
        //通过套系的id得到商品的id
        List<Goods_InfoToPackage> infoToPackageList = dao.getGoodsInfoToPackageByPackageId(id);
        for (Goods_InfoToPackage infoToPackage : infoToPackageList) {
            Goods_Info info = dao.getGoodsInfo(infoToPackage.getGoodsinfoId());
            goods_infoList.add(info);
        }
        return goods_infoList;  //To change body of created methods use File | Settings | File Templates.
    }
}
